<!DOCTYPE HTML>
<html>
<head>
    <include file="Home@default/Index/header"/>
</head>
<body>
<!--在这里编写你的代码-->
<div style="background-color: #e9ecf3">
    <div data-am-sticky="{animation: 'slide-top'}">
        <div class="am-btn am-btn-primary am-u-sm-12 am-u-md-4 am-u-md-offset-8 am-u-lg-2 am-u-lg-offset-10">
            剩余时间：<span id="countdown_time"></span><span class="countdown_text">分钟</span>
        </div>
    </div>
    <div style="clear: both;"></div>
    <div class="am-u-sm-12" style="background-color: #e9ecf3">

        <form class="am-form " action="<{:U('Index/ExamResult');}>" method="post" style="margin: auto 3% auto 3%;">
            <input type="hidden" name="assignmentid" value="<{$assignmentid}>">
            <input type="hidden" name="studentexamresult" value="<{$studentexamresult}>">
            <h2 align="center"><{$examtitle}></h2>
            <div class="am-u-lg-offset-1 am-u-lg-10">
                <foreach name="ret_exam" item="ret_exam_vo">
                    <h3><{$ret_exam_vo.titleNumer.title_explain|htmlspecialchars_decode}></h3>
                    <foreach name="ret_exam_vo.data" item="vo" key="k">
                        <php> $voi = unserialize($vo['options']);</php>
                        <if condition="$vo.type eq 1">
                            <include file="QuestionTypes/Radio"/>
                            <elseif condition="$vo.type == 2"/>
                            <include file="QuestionTypes/CheckBox"/>
                            <elseif condition="$vo.type == 3"/>
                            <include file="QuestionTypes/Fill"/>
                            <elseif condition="$vo.type == 4"/>
                            <include file="QuestionTypes/ShortAnswer"/>
                            <elseif condition="$vo.type == 5"/>
                            <include file="QuestionTypes/built-in"/>
                        </if>
                    </foreach>
                </foreach>
                <div class="am-form-group">
                    <div align="center">
                        <button type="submit" class="am-btn am-btn-primary btn-loading-example"
                                data-am-loading="{spinner: 'circle-o-notch', loadingText: '加载中...', resetText: '加载过了'}">
                            提交
                        </button>
                    </div>
                </div>
            </div>
        </form>
    </div>
</div>
<include file="Home@default/Index/footer"/>
<script src="__PUBLIC__/BeginnerAdmin/plugins/layer_mobile/layer.js"></script>
<script>
    $(function () {
        //设置时间倒计时
        setCountDown_time(<{$duration/60|intval}>,<{$duration%60|intval}>);
    });
    /*时间倒计时*/
    var sec = 0, min = 0, tmp_clock = 300;
    var idt;
    var format = function (str) {
        if (parseInt(str) < 10) {
            return "0" + str;
        }
        return str;
    };

    function setCountDown_time(m=0, s=0) {
        sec = s , min = m;
        idt = window.setInterval("ls();", 1000);
    }

    function ls() {
        sec--;
        if (sec == 0) {
            min--;
            sec = 59;
        } else if (sec < 0) {
            min--;
            sec = 60 + sec;
        }
        if (min < 0) {
            window.clearInterval(idt);
            submit();
            document.getElementById("countdown_time").innerHTML = format(0) + ":" + format(0);
        } else {
            document.getElementById("countdown_time").innerHTML = format(min) + ":" + format(sec);
        }

        if (tmp_clock > 0) {
            tmp_clock--;
        } else {
            tmp_clock = 3;
            $.get("<{:U('index/RemainingTestTime');}>", {studentexamresultid: "<{$studentexamresult}>"}, function (data) {
                if (data.code == 200) {
                    window.clearInterval(idt);
                    setCountDown_time(data.remainingtesttime.m, data.remainingtesttime.s);
                    tmp_clock = 300;
                } else {
                    tmp_clock = 10;
                }
            }, 'json');

        }
    }

    var answer;

    function MyStorage(tid, ret) {
        answer[tid] = ret;
        storage.setItem('answer', JSON.stringify(answer));
    }

    //单选处理
    function radio_select(id, value) {
        $('input:radio[name="answer[' + id + ']"]').removeAttr('checked');
        $("input:radio[name='answer[" + id + "]'][value='" + value + "']").attr("checked", true);
        radio_onclick(id);
    }

    function radio_onclick(tid) {
        var is_rod = $(".id-" + tid);
        var zhi = is_rod.filter(':checked').val();
        $("#td-id-" + tid + "-a").removeClass('am-primary');
        $("#td-id-" + tid + "-b").removeClass('am-primary');
        $("#td-id-" + tid + "-c").removeClass('am-primary');
        $("#td-id-" + tid + "-d").removeClass('am-primary');
        $("#td-id-" + tid + "-" + zhi).addClass('am-primary');
    }

    //多选处理
    function checkbox_onclick(id, value) {
        if ($("input:checkbox[name='answer[" + id + "][]'][value='" + value + "']").is(":checked")) {
            $("input:checkbox[name='answer[" + id + "][]'][value='" + value + "']").attr("checked", false);
            $("#td-id-" + id + "-" + value).removeClass('am-primary');
        } else {
            $("input:checkbox[name='answer[" + id + "][]'][value='" + value + "']").attr("checked", true);
            $("#td-id-" + id + "-" + value).addClass('am-primary');
            //is_rod.addClass('am-primary');
        }

    }

    $(function () {
        $('.btn-loading-example').click(function () {
            var $btn = $(this);
            $btn.button('loading');
            setTimeout(function () {
                $btn.button('reset');
            }, 5000);
        });

        $("form").submit(function (data) {
            console.log($("form").serialize());
            submit();
            return false;
        });
    });

    function submit() {
        $.post("<{:U('Index/ExamResult');}>", $("form").serialize(), function (data) {
            if (data.code == 200) {
                layer.open({
                    content: data.msg
                    , btn: '我知道了'
                    , yes: function () {
                        window.location = '<{:U('Home/Index/Index');}>';
                    }
                });

            } else {
                layer.open({
                    content: data.msg
                    , btn: '我知道了'
                });
            }
        }, 'json');
    }

</script>
</body>
</html>